package com.hxs.hxsserver.controller.device;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hxs.hxsserver.controller.BaseController;
import com.hxs.hxsserver.domain.dto.IdDTO;
import com.hxs.hxsserver.domain.dto.JsonResult;
import com.hxs.hxsserver.domain.dto.PageBaseDto;
import com.hxs.hxsserver.domain.dto.device.*;
import com.hxs.hxsserver.domain.entity.device.DeviceStatusHistory;
import com.hxs.hxsserver.service.DeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 * 设备管理
 * @author liuchuan
 * @create 2024/9/26
 */
@Slf4j
@RestController
@Api(value = "设备管理")
@RequestMapping("deviceManage")
public class DeviceController extends BaseController {
    @Resource
    DeviceService deviceService;

    @GetMapping("/getDeviceList")
    @ApiOperation(value = "获取设备列表")
    public JsonResult<IPage<DeviceDTO>> getDeviceList(@ApiParam(value = "查询参数") @Validated DeviceListQueryDTO deviceListQueryDTO){
        return JsonResult.success(deviceService.getDeviceList(deviceListQueryDTO,getUser()));
    }

    @PostMapping("/updateDeviceById")
    @ApiOperation(value = "更新设备数据")
    public JsonResult<Boolean> updateDeviceById(@RequestBody @Validated DeviceDTO dto){
        return JsonResult.success(deviceService.updateDeviceById(dto));
    }

    @PostMapping("/insertDevice")
    @ApiOperation(value = "新增设备")
    public JsonResult<Boolean> insertDeviceById(@RequestBody @Validated DeviceDTO dto) {
        return JsonResult.success(deviceService.insertDeviceById(dto,getUser()));
    }

    @GetMapping("/getDeviceById")
    @ApiOperation(value = "获取设备信息")
    public JsonResult<DeviceDTO> getDeviceById(@Validated IdDTO idDTO){
        return JsonResult.success(deviceService.getDeviceById(idDTO));
    }

    @PostMapping("/deleteDeviceById")
    @ApiOperation(value = "删除设备")
    public JsonResult<Boolean> deleteDeviceById(@RequestBody @Validated IdDTO idDTO){
        return JsonResult.success(deviceService.deleteDeviceById(idDTO));
    }

    @GetMapping("/getDeviceTree")
    @ApiOperation(value = "获取设备树")
    public JsonResult<List<DeviceFolderTree>> getDeviceTree(){
        return JsonResult.success(deviceService.getDeviceTree(getUser()));
    }

    @PostMapping("/insertFolder")
    @ApiOperation(value = "新增文件夹")
    public JsonResult<Boolean> insertFolder(@RequestBody @Validated FolderDTO folderDTO){
        return JsonResult.success(deviceService.insertFolder(folderDTO,getUser()));
    }

    @PostMapping("/updateFolder")
    @ApiOperation(value = "编辑文件夹")
    public JsonResult<Boolean> updateFolder(@RequestBody @Validated FolderDTO folderDTO){
        return JsonResult.success(deviceService.updateFolder(folderDTO));
    }

    @PostMapping("/deleteFolder")
    @ApiOperation(value = "删除文件夹")
    public JsonResult<Boolean> deleteFolder(@RequestBody @Validated IdDTO idDTO){
        return JsonResult.success(deviceService.deleteFolder(idDTO));
    }


    @GetMapping("/getDeviceStatusHisList")
    @ApiOperation(value = "获取设备离线在线历史")
    public JsonResult<IPage<DeviceStatusHistory>> getDeviceStatusHisList(@ApiParam(value = "查询参数") @Validated DeviceStatusQueryDTO deviceListQueryDTO){
        return JsonResult.success(deviceService.getDeviceStatusHisList(deviceListQueryDTO));
    }

    @GetMapping("/getDeviceNum")
    @ApiOperation(value = "获取设备总数")
    public JsonResult<RutrunDeviceNumDTO> getDeviceNum(){
        return JsonResult.success(deviceService.getDeviceNum(getUser()));
    }
}
